#coding=utf-8 
'''
Created on 2012-8-28
@author: gazhang
'''
#http://blog.csdn.net/v_JULY_v/article/details/6057286
#problem 30-39

#30
#在从1到n的正数中1出现的次数（数组）
#题目：输入一个整数n，求从1到n这n个整数的十进制表示中1出现的次数。
def Cal1ToNum(n):
    count = 0
    length = len(str(n))
    for i in range(1, length + 1):
        base = pow(10, i)
        p = n / base
        q = n % base
        if q / pow(10, i - 1) >= 2:
            count = count + pow(10, i - 1)
        elif q / pow(10, i - 1) == 1:
            count = count + q % pow(10, i - 1) + 1
        count = count + p
    return count

#35.求一个矩阵中最大的二维矩阵(元素和最大).如:
#1 2 0 3 4
#2 3 4 5 1
#1 1 5 3 0
#中最大的是:
#4 5
#5 3
def findMaxTwoDimension(_tuple):
    l1=len(_tuple)
    l2=len(_tuple[0])
    i=0
    j=0
    maxX=-1
    maxY=-1
    max=-1
    sum=0
    while i<l1-1:
        while(j<l2-1):
            sum=_tuple[i][j]+_tuple[i][j+1]+_tuple[i+1][j]+_tuple[i+1][j+1]
            if sum>max:
                maxX=i
                maxY=j
                max=sum
            j=j+1
        j=0
        i=i+1
    return (maxX,maxY,max)  

print Cal1ToNum(12)
print findMaxTwoDimension(((1,2,0,3,4),(2,3,4,5,1),(1,1,5,3,0)))
